using System;
using System.Collections.Generic;
using YakShaver.WCSF.BuildManager.Interface.BusinessEntities;
using YakShaver.WCSF.BuildManager.Interface.Services;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using YakShaver.WCSF.BuildManager.BusinessEntities;

namespace YakShaver.WCSF.BuildManager
{
    public class BuildManagerController : IBuildManagerController
    {

        private IProjectService _buildService;
        private ISandboxService _sandboxService;

        /// <summary>
        /// Wow I must admit this MVP framework is pretty wicked.
        /// </summary>
        /// <param name="buildService"></param>
        public BuildManagerController([ServiceDependency] IProjectService buildService, 
            [ServiceDependency] ISandboxService sandboxService)
        {
            _buildService = buildService;
            _sandboxService = sandboxService;
        }


        #region IBuildManagerController Members

        public IList<IProject> GetProjects()
        {
            return _buildService.GetProjects();
        }

        #endregion

        #region IBuildManagerController Members


        public IList<IProjectBuild> GetProjectBuilds(string projectId)
        {
            return _buildService.GetProjectBuilds(projectId);
        }

        #endregion

        #region IBuildManagerController Members


        public IProjectSandbox CreateSandbox(IProjectBuild projectBuild, string sandboxName)
        {
            string webUrl = string.Format("{0}_{1}_{2}", 
                projectBuild.Project.BuildName, projectBuild.Label, sandboxName);

            // Call The Sandbox Service to create it

            IDictionary<string, object> sandboxProperties = new Dictionary<string,object>();
            sandboxProperties.Add("webUrl", webUrl);

            IProjectSandbox sandbox = _sandboxService.CreateSandbox(projectBuild, sandboxProperties, _buildService);

            return sandbox;
        }

        #endregion



        #region IBuildManagerController Members


        public IProjectSandbox CreateSandbox(IProjectBuild projectBuild)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
